﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;

using Tradex.ComponentModel;

namespace Tradex.Market {

    /// <summary>
    /// This class uniquely identifies an instrument.
    /// </summary>
    [Serializable ()]
    public sealed class InstrumentKey : Key<Instrument> {

        /// <summary>
        /// Public constructor taking all values.
        /// </summary>
        /// <param name="market"></param>
        /// <param name="instrument"></param>
        public InstrumentKey(string market, string instrument) {
            Market = market;
            Instrument = instrument;
        }

        /// <summary>
        /// Gets the Market of the InstrumentKey.
        /// </summary>
        public string Market { get; private set; }

        /// <summary>
        /// Gets the Instrument of the InstrumentKey
        /// </summary>
        public string Instrument { get; private set; }

        /// <inheritdoc />
        public override string ToString() {
            return String.Format(CultureInfo.InvariantCulture, "{0}@{1}", Instrument, Market);
        }

        /// <inheritdoc />
        public override int GetHashCode() {
            return base.GetHashCode();
        }

        /// <inheritdoc />
        public override bool Equals (object obj) {
            InstrumentKey kObj = obj as InstrumentKey;
            if (kObj == null) {
                return false;
            }
            return kObj == this;
        }

        /// <inheritdoc />
        [System.Diagnostics.CodeAnalysis.SuppressMessage ("Microsoft.Design", "CA1062")]
        public static bool operator == (InstrumentKey left, InstrumentKey right) {
            if (Object.ReferenceEquals (left, right)) {
                return true;
            }
            if (Object.ReferenceEquals (right, null)) {
                return false;
            }           
            if (left.Instrument != right.Instrument) {
                return false;
            }
            if (left.Market != right.Market) {
                return false;
            }
            return true;
        }

        /// <inheritdoc />
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062")]
        public static bool operator != (InstrumentKey left, InstrumentKey right) {
            if (Object.ReferenceEquals(left, right)) {
                return true;
            }
            if (Object.ReferenceEquals(right, null)) {
                return false;
            }      
            if (left.Instrument != right.Instrument) {
                return true;
            }
            if (left.Market != right.Market) {
                return true;
            }
            return false;
        }

    }

}
